class User < ActiveRecord::Base
  validates_uniqueness_of :user_name, :message => (I18n.t :currently_exists)
  validates_presence_of :user_name, :message => (I18n.t :can_not_be_empty)

  validates_presence_of :password, :message => (I18n.t :can_not_be_empty)
  validates_confirmation_of :password, :message => (I18n.t :check_your_password)

  has_many :words, :class_name => "Word", :dependent => :destroy, :autosave => true, :foreign_key => :user_id

  before_save :crypt

  def crypt
    self.password = Digest::MD5.hexdigest(password)
  end

  def password_matches?(password_to_match)
    self.password == Digest::MD5.hexdigest(password_to_match)
  end
end